package
{
	import com.adobe.crypto.MD5;
	
	import flash.net.ObjectEncoding;
	import flash.utils.ByteArray;
	
	//import com.hurlant.crypto.hash.MD5;
	
	
	public class ChallengeResponse //extends ByteArray
	{
		public var response;
		
		
		public function ChallengeResponse(challenge,password)
		{
			super();
			//objectEncoding = ObjectEncoding.AMF0;
			var hashedPassword = StreamTools.hex2ascii(MD5.hash(password));
		    //var hashedPassword = MD5.hash(password);
			//trace("hashedPassword = "+hashedPassword);
		    //var doubleHashedPassword = StreamTools.hex2ascii(MD5.hash(hashedPassword+challenge));
		    var doubleHashedPassword = MD5.hash(hashedPassword+challenge);
		    //trace("doubleHashedPassword = "+doubleHashedPassword);
		    
		    
		    // need to convert string back to ascii
		    //byteString = new ByteArray();
		    //writeMultiByte(doubleHashedPassword,'us-ascii');
		    response = doubleHashedPassword;
		    ////trace("doubleHashedPassword ba = "+ ba.toString());
		}
		
		public function valueOf():Object
		{
			//return readMultiByte(0,'us-ascii');
			return response;
		}

	}
}